package com.zhongke.DKYCboot.controller;

import com.zhongke.DKYCboot.bean.BaseCar;
import com.zhongke.DKYCboot.bean.BaseDriver;
import com.zhongke.DKYCboot.bean.PersonCar;
import com.zhongke.DKYCboot.service.PersonCarService;
import com.zhongke.DKYCboot.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/PersonCar")
public class PersonCarContrller {
    @Autowired
    private PersonCarService personCarService;

    @RequestMapping(value = "/insertPersonCar" ,method = RequestMethod.POST)
    public Msg insertPerson(Integer car_id, Integer driver_id){
        String create_time = "";
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        create_time = df.format(new Date());
        PersonCar personCar = new PersonCar(driver_id, car_id, 0, create_time);
        return personCarService.insertPersonCar(personCar);
    }

    @RequestMapping(value = "/selectPersonCar" ,method = RequestMethod.POST)
    public Msg selectPersonCar(BaseCar basecar, BaseDriver baseDriver, Integer pageNum, Integer pageSize){
        PersonCar personCar = new PersonCar();
        personCar.setBasecar(basecar);
        personCar.setBaseDriver(baseDriver);
        return personCarService.selectPersonCar(personCar, pageNum, pageSize);
    }

    @RequestMapping(value = "/updatePersonCar" ,method = RequestMethod.POST)
    public Msg updatePersonCar(Integer car_id, Integer driver_id, Integer car_flag){
        PersonCar personCar = new PersonCar(driver_id, car_id, car_flag);
        return personCarService.updatePersonCar(personCar);
    }

}
